Skip to content

Conversation

barucden
Copy link
Contributor

When running julia with --check-bounds=no, the package fails to precompile. The reason is that compiler elides @boundschecks, which in this case removes buffer reallocation. I believe that's unwanted.

Issue was reported on Discourse by 0samuraiE.

@nhz2
Copy link
Contributor

nhz2 commented Apr 30, 2025

Does this have any impact on performance when Julia is run normally?

Particularly for code using:

@inbounds @writechar bytes[i]

@inbounds @writechar bytes[i]

@inbounds @writechar '"'

@inbounds @writechar '"'

@barucden
Copy link
Contributor Author

Does this have any impact on performance when Julia is run normally?

Can you suggest a representative benchmark I could run? Is it enough to just print the JSON representation of bunch of numbers?

I tried the following:

using JSON3, BenchmarkTools

struct T
    a::Int
    b::Float64
    c::String
    null::Nothing
    maybe::Union{Int, Nothing}
end

t = T(1232423567890, 12.345678901234, "ABCDEFGHIJKLMNOPQRSTUVXYZ", nothing, 1234567890123)
@btime JSON3.write(IOBuffer(), $t)

I observe the following measurements:

  422.397 ns (15 allocations: 992 bytes) # with @boundcheck
  424.176 ns (15 allocations: 992 bytes) # without @boundscheck

Should I also update the CI action versions so that the tests run?

@barucden
Copy link
Contributor Author

Action versions updated.

nhz2 and others added 2 commits May 4, 2025 10:49
When running julia with `--check-bounds=no`, the package fails to
precompile. The reason is that compiler elides `@boundscheck`s, which in
this case removes buffer reallocation. I believe that's unwanted.

Issue was [reported on
Discourse](https://discourse.julialang.org/t/json3-fails-to-precompile-due-to-embedded-nuls-in-c-strings/128482) by 0samuraiE.
@barucden
Copy link
Contributor Author

barucden commented May 5, 2025

I rebased to the branch containing Nathan's fixes from #312. So this PR should be merged after #312.

@quinnj quinnj merged commit e95b748 into quinnj:main May 23, 2025
4 of 5 checks passed
@barucden barucden deleted the boundscheck branch May 23, 2025 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants